4 import java.awt.Rectangle;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.rmi.Naming;
8 import java.rmi.RemoteException;
9 import java.util.Enumeration;
10 import java.util.Vector;
12 import javax.swing.JButton;
13 import javax.swing.JFrame;
14 import javax.swing.JLabel;
15 import javax.swing.JPanel;
16 import javax.swing.JScrollPane;
17 import javax.swing.JTable;
18 import javax.swing.border.EmptyBorder;
19 import javax.swing.table.DefaultTableModel;
21 import common.AdminInterface;
22 import common.HouseInterface;
24 import configuration.___IntNames;
25 import domain.RuralHouse;
27 public class listOfRemovalRequestsGUI extends JFrame {
32 private static final long serialVersionUID = 1L;
33 private JPanel contentPane;
35 private DefaultTableModel tableModel;
36 private AdminInterface am = null;
37 private Vector<RuralHouse> houses;
42 public listOfRemovalRequestsGUI() {
44 am = (AdminInterface) Naming.lookup(___IntNames.AdminManager);
45 } catch (Exception e1) {
46 System.out.println("Error accessing remote authentication: "
49 setTitle("Deleting requests");
51 this.houses = am.getDeletionRequests();
53 } catch (Exception e) {
58 private void init() throws Exception {
59 setBounds(100, 100, 600, 450);
60 contentPane = new JPanel();
61 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
62 setContentPane(contentPane);
63 contentPane.setLayout(null);
65 JLabel lblNewLabel = new JLabel();
66 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
67 lblNewLabel.setBounds(23, 41, 536, 33);
68 contentPane.add(lblNewLabel);
70 lblNewLabel.setText("There are not houses to be deleted");
72 lblNewLabel.setText("List of houses to be deleted:");
73 JScrollPane scrollPane = new JScrollPane();
74 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
75 scrollPane.setBounds(23, 113, 536, 271);
76 contentPane.add(scrollPane);
78 table = new JTable() {
79 private static final long serialVersionUID = 1L;
81 public boolean isCellEditable(int row, int column) {
85 scrollPane.setViewportView(table);
86 tableModel = new DefaultTableModel(null, new String[] { "House Name",
87 "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" });
89 table.setModel(tableModel);
90 Enumeration<RuralHouse> en = houses.elements();
92 JButton btnNewButton = new JButton("Confirm Deletion");
93 btnNewButton.addActionListener(new ActionListener() {
94 public void actionPerformed(ActionEvent e) {
95 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
96 HouseInterface hm = null;
98 hm = (HouseInterface) Naming
99 .lookup(___IntNames.HouseManager);
100 } catch (Exception e1) {
102 .println("Error accessing remote authentication: "
105 RuralHouse rh = houses.get(table.getSelectedRow());
108 hm.removeHouse(rh, rh.getOwner());
109 am.removeHouseDeletionRequests(rh);
111 } catch (RemoteException e1) {
112 // TODO Auto-generated catch block
113 e1.printStackTrace();
115 ((DefaultTableModel) table.getModel()).removeRow(houses
121 btnNewButton.setBounds(90, 396, 169, 25);
122 contentPane.add(btnNewButton);
124 JButton btnNewButton_1 = new JButton("Deny Deletion");
125 btnNewButton_1.addActionListener(new ActionListener() {
126 public void actionPerformed(ActionEvent e) {
127 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
128 RuralHouse rh = houses.get(table.getSelectedRow());
129 ((DefaultTableModel) table.getModel()).removeRow(houses
133 am.removeHouseDeletionRequests(rh);
135 } catch (RemoteException e1) {
136 // TODO Auto-generated catch block
137 e1.printStackTrace();
143 btnNewButton_1.setBounds(291, 396, 169, 25);
144 contentPane.add(btnNewButton_1);
145 while (en.hasMoreElements()) {
146 rh = en.nextElement();
147 Vector<Object> row = new Vector<Object>();
148 row.add(rh.getHouseName());
149 row.add(rh.getFeatures().getnRooms());
150 row.add(rh.getFeatures().getnKitchens());
151 row.add(rh.getFeatures().getnBaths());
152 row.add(rh.getFeatures().getnParkings());
153 row.add(rh.getFeatures().getnLivings());
154 tableModel.addRow(row);